package com.csw.spark

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.rdd.RDD

//2、统计学生的总分
object Text2 {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
      .setMaster("local")
      .setAppName("text1")

    val sc: SparkContext = new SparkContext(conf)

    val scoresRDD: RDD[String] = sc.textFile("spark/data/score.txt")

     val scoresIdScoreRDD: RDD[(String, Int)] = scoresRDD.map(i=>(i.split(",")(0),i.split(",")(2).toInt))

    val scoreSumRDD: RDD[(String, Int)] = scoresIdScoreRDD.reduceByKey(_+_)

    scoreSumRDD.foreach(println)
  }

}
